﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StuManagementSystem
{
    public partial class frm_SubjectList : Form
    {
        DbContext db = new DbContext();
        private string sql1 = @"SELECT StuSubjectName,StuSubjectHour,StuGradeName 
                            FROM	dbo.StuSubject,dbo.StuGrade WHERE 
                            StuGrade.StuGradeId = StuSubject.StuGradeId and 1=1 ";
        public frm_SubjectList()
        {
            InitializeComponent();
        }


        #region 窗口预加载
        /// <summary>
        /// 窗口预加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frm_SubjectList_Load(object sender, EventArgs e)
        {
            //DataGridView整行选中
            this.dgv_ShowSubject.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            //DataGridView不允许出现空行
            this.dgv_ShowSubject.AllowUserToAddRows = false;
            //不允许多选
            this.dgv_ShowSubject.MultiSelect = false;
            ShowSubject(sql1);
        }

        #endregion

        #region 显示科目信息
        /// <summary>
        /// 显示科目信息
        /// </summary>
        /// <param name="sql"></param>
        private void ShowSubject(string sql)
        {
            var ds = db.ExecDataSet(sql);
            this.dgv_ShowSubject.DataSource = ds.Tables[0];
        }
        #endregion

        #region 双击控件时事件
        /// <summary>
        /// 双击控件时事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var No = this.treeView1.SelectedNode;
            var sql = "";
            if (No.Text == "全部")
                return;
            else
                sql = string.Format(sql1 + @" and dbo.StuGrade.StuGradeId = {0}", No.Name);
            ShowSubject(sql);
        }
        #endregion
        


    }
}
